/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('openplatform', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AuthorizeFileUploadRequest {
  product?: string(name='Product'),
  regionId?: string(name='RegionId'),
}

model AuthorizeFileUploadResponseBody = {
  accessKeyId?: string(name='AccessKeyId'),
  bucket?: string(name='Bucket'),
  encodedPolicy?: string(name='EncodedPolicy'),
  endpoint?: string(name='Endpoint'),
  objectKey?: string(name='ObjectKey'),
  requestId?: string(name='RequestId'),
  signature?: string(name='Signature'),
  useAccelerate?: boolean(name='UseAccelerate'),
}

model AuthorizeFileUploadResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: AuthorizeFileUploadResponseBody(name='body'),
}

async function authorizeFileUploadWithOptions(request: AuthorizeFileUploadRequest, runtime: $RuntimeOptions): AuthorizeFileUploadResponse {
  request.validate();
  var query = OpenApiUtil.query(request.toMap());
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'AuthorizeFileUpload',
    version = '2019-12-19',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'GET',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function authorizeFileUpload(request: AuthorizeFileUploadRequest): AuthorizeFileUploadResponse {
  var runtime = new $RuntimeOptions{};
  return authorizeFileUploadWithOptions(request, runtime);
}

